<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/8
 * Time: 16:47
 */

namespace app\admin\controller;
use app\admin\Controller;
use app\common\model\GasStation as modelGasStation;
\think\Loader::import('controller/Controller', \think\Config::get('traits_path'), EXT);

class GasStation extends Controller
{
    use \app\admin\traits\controller\Controller;

    public function index()
    {
        if ($this->request->method() == "GET") {
            $where = [
                'isdelete' => 0
            ];
            $keyword = $this->request->param('keyword');
            $listRows = 20;
            $filed = "*";
            $model = new modelGasStation();
            $list = $model->getGasStationList($where, $filed, $listRows, $this->request, $keyword);
            $this->view->assign('list', $list);
            $this->view->assign("count", $list->total());
            $this->view->assign("page", $list->render());
            $this->view->assign('numPerPage', $list->listRows());
        }
        return $this->view->fetch();
    }

    public function detail()
    {
        if ($this->request->method() == "GET") {
            $id = $this->request->param("id");
            $where = [
                'id' => $id,
                'isdelete' => 0,
            ];

            $model = new modelGasStation();
            $field = "*";
            $data = $model->getGasStationInfo($where, $field);

            $this->view->assign('vo', $data);
        }
        return $this->view->fetch();
    }


    public function edit() {
        if ($this->request->method() == "GET") {
            $id = $this->request->param("id");
            $where = [
                'id' => $id,
                'isdelete' => 0,
            ];

            $model = new modelGasStation();
            $field = "*";
            $data = $model->getGasStationInfo($where, $field);

            $this->view->assign('vo', $data);
        }
        return $this->view->fetch();
    }

    public function uploadInfo () {

        if ($this->request->method() == "POST") {
            $param = $this->request->param();

            $where['id'] = $param['id'];
            $where['isdelete'] = 0;

            unset($param['id']);

            $model = new modelGasStation();
            $data = $model->updateGasStationInfo($where, $param);
            if ($data) {
                return ajax_return_adv("编辑成功", '', '编辑成功');
            } else {
                return ajax_return_adv("编辑失败", '', '编辑失败');
            }

        }
    }

    public function recyclebin() {
        if ($this->request->method() == "GET") {
            $where = [
                'isdelete' => 1
            ];
            $keyword = $this->request->param('keyword');
            $listRows = 20;
            $filed = "*";
            $model = new modelGasStation();
            $list = $model->getGasStationList($where, $filed, $listRows, $this->request, $keyword);
            $this->view->assign('list', $list);
            $this->view->assign("count", $list->total());
            $this->view->assign("page", $list->render());
            $this->view->assign('numPerPage', $list->listRows());
        }
        return $this->view->fetch();
    }

    public function add() {
         return $this->view->fetch();
    }

    public function addGasStationInfo() {
        $param = $this->request->param();
        $param['create_time'] = date("Y-m-d H:i:s", time());

        $model = new modelGasStation();
        $data = $model->addGasStationInfo($param);
        if ($data) {
            return ajax_return_adv("添加成功");
        } else {
            return ajax_return_adv("添加失败");
        }
    }
}
